import {ModalForm, ProFormSelect, ProFormText} from '@ant-design/pro-components';


export interface FormValueType extends Partial<API.WebHookEdit> {
  target?: string;
  template?: string;
  type?: string;
  time?: string;
  frequency?: string;
}


export interface EditFormProps {
  onOpenChange: (flag?: boolean, formVals?: FormValueType) => void;
  onSubmit: (values: FormValueType) => Promise<void>;
  editModalVisible: boolean;
  values: Partial<API.WebHookEdit>;
  appEnum?: Partial<Record<string, { text: string; status: string }>>;
}


export default (props:EditFormProps) => {
  return (
      <ModalForm
        title="编辑webhook"
        open={props.editModalVisible}
        onOpenChange={props.onOpenChange}
        onFinish={props.onSubmit}
        initialValues={props.values}
    >
      <ProFormText
        width="md"
        name="id"
        label="Id"
        hidden={true}
        disabled={true}
      />
      <ProFormText
        width="md"
        name="name"
        label="名称"
        rules={[
          { required: true, message: '请输入名称！' },
        ]}
      />
      <ProFormText
        name="url"
        width="md"
        label="url"
        rules={[
          { required: true, message: '请输入url！' },
        ]}
      />
      <ProFormText
        width="md"
        name="secret"
        label="密码密钥"
        rules={[{ required: true, message: '请输入密码密钥！' }]}
      />
      <ProFormSelect
          name="secretType"
          width="md"
          label="签名类型"
          valueEnum={{
            'SIGNING_KEY': {text: '签名密钥', status: 'SIGNING_KEY'},
            'PASSWORD': {text: '密码', status: 'PASSWORD'},
          }}
        rules={[{required: true, message: '请输入签名类型'}]}
      />
      <ProFormSelect
        width="md"
        name="app"
        label="app"
        valueEnum={props.appEnum}
        rules={[{ required: true, message: '请输入app！' }]}
      />
    </ModalForm>
  );
};
